﻿using System;
using System.Collections.Generic;

using Gonte;
using Gonte.Validation;

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace MyUtilitiesTest
{
    /// <summary>
    ///This is a test class for ExceptionThrowerTest and is intended
    ///to contain all ExceptionThrowerTest Unit Tests
    ///</summary>
    [TestClass()]
    public class ExceptionThrowerTest
    {
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        [TestMethod()]
        [ExpectedException(typeof(ArgumentNullException))]
        public void ExceptionThrowerThrowWhenNullAndNullValueTest()
        {
            Object value = null;
            ExceptionThrower.ThrowWhenNull("value", value);
        }

        [TestMethod()]
        public void ExceptionThrowerThrowWhenNullAndNotNullValueTest()
        {
            Object value = new Object();
            ExceptionThrower.ThrowWhenNull("value", value);
        }

        [TestMethod()]
        [ExpectedException(typeof(ArgumentNullException))]
        public void ExceptionThrowerThrowWhenNullOrEmptyAndNullValueTest()
        {
            String value = null;
            ExceptionThrower.ThrowWhenNullOrEmpty("value", value);
        }

        [TestMethod()]
        [ExpectedException(typeof(ArgumentNullException))]
        public void ExceptionThrowerThrowWhenNullOrEmptyAndEmptyValueTest()
        {
            String value = "";
            ExceptionThrower.ThrowWhenNullOrEmpty("value", value);
        }

        [TestMethod()]
        public void ExceptionThrowerThrowWhenNullOrEmptyAndEmptyButNotEmptyValueTest()
        {
            String value = "Not Empty";
            ExceptionThrower.ThrowWhenNullOrEmpty("value", value);
        }

        /// <summary>
        /// Invalid test object
        /// </summary>
        public class InvalidObject
            : IValidable
        {
            #region IValidable Members

            public bool Validate(ref List<ValidationError> errors)
            {
                errors.Add(new ValidationError("SomeProperty", "Some error"));
                return false;
            }

            #endregion
        }

        [TestMethod()]
        [ExpectedException(typeof(ValidationException))]
        public void ExceptionThrowerThrowWhenNotValidObjectTest()
        {
            InvalidObject @object = new InvalidObject();
            ExceptionThrower.ThrowWhenNotValid(@object);
        }

        [TestMethod()]
        public void ExceptionThrowerThrowWhenNotValidButValidObjectTest()
        {
            Object @object = new Object();
            ExceptionThrower.ThrowWhenNotValid(@object);
        }

        [TestMethod()]
        [ExpectedException(typeof(InvalidOperationException))]
        public void ExceptionThrowerThrowWhenTest()
        {
            ExceptionThrower.ThrowWhen(true, "Test error message");
        }

        [TestMethod()]
        public void ExceptionThrowerThrowWhenAndNotTest()
        {
            ExceptionThrower.ThrowWhen(false, "Test error message");
        }

        [TestMethod()]
        [ExpectedException(typeof(InvalidOperationException))]
        public void ExceptionThrowerThrowWhenNotTest()
        {
            ExceptionThrower.ThrowWhenNot(false, "Test error message");
        }

        [TestMethod()]
        public void ExceptionThrowerThrowWhenNotAndYesTest()
        {
            ExceptionThrower.ThrowWhenNot(true, "Test error message");
        }
    }
}
